<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
	<title>菜单管理</title>
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath()%>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/js/bootstrap.js" type="text/javascript"></script>  
    
        
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrapValidator.css"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrapValidator.js"></script>
    
    
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/lhdialog/lhgcore.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/lhdialog/lhgdialog.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/OpenDialog.js"></script>

    <script type="text/javascript">
    $(document).ready(function() {
    	for(var i=1;i<4;i++){
    		
    		if($("#value"+i).val()==undefined){
    			$("#label"+i).after('<div class="col-sm-2"><input class="form-control" type="text" name="list['+(i-1)+'].value"></div>');
    		}
    	}
    	
    	$('#defaultForm')
        .bootstrapValidator({
            message: 'This value is not valid',
            fields: {
                "t.value": {
                    validators: {
                        notEmpty: {
                            message: '属性值不能为空'
                        }
                    }
                },
                "t.type": {
                    validators: {
                        notEmpty: {
                            message: '属性值类型不能为空'
                        }
                    }
                }
            }
        })
    });
    
   //增加
   function addProductAttrDict(){
	   $("#defaultForm").action="productAttrDict/ProductAttrDict_addProductAttrDict";
	   $("#defaultForm").submit();
   }
    
  //选择leibiue界面（弹出框）
    function chooseAttr(){
	var flag =1;
	var page = 	"<%=request.getContextPath()%>/productAttr/ProductAttr_getWithoutDictListByPage.action?params=choose";
	if(flag == 1){
		var titleText = "";
		PUBLICOBJECT.id = "entid";
		PUBLICOBJECT.title = titleText;
		PUBLICOBJECT.width = "1000";
		PUBLICOBJECT.height = "auto";
		PUBLICOBJECT.titleText = titleText;
		PUBLICOBJECT.page = page;
		var rs = PUBLICOBJECT.openLab();
		rs.ShowDialog();// 打开弹出窗
		var dom = window.frames["lhgfrm_" + PUBLICOBJECT.id];// 弹出框document对象
		rs.addBtn(PUBLICOBJECT.id, "确定", function() {
			var _choose = $(dom.document).find("input[name='idChoose']:checked");//获取到被选择的组织ＩＤ
			var chooseValue = _choose.val();
			if(chooseValue != null){
				rs.cancel();// 关闭当弹出窗
				var chooseName = _choose.siblings("input[name='nameChoose']").val();//获取到被选择的组织名称
				$("#productAttrName").trigger("onchange");//触发productAttrName的onchang事件
				    $("#productAttrName").val(chooseName);
			    	$("#productAttrId").val(chooseValue);
			}else{
				alert("请选择一项");
			}
		}, "left");
	
	}

}
  
      var flog=false;
      
	
	  function checkAttrName(){
		    var productAttrName=$("#productAttrName").val();
			productAttrName=productAttrName.trim();
		  if(productAttrName!="" || productAttrName!=null){
			    $("#productAttrNameMng").attr("style","color:#3c763d");
	    		$("#productAttrName").attr("style","border:1px solid #3c763d");
				$("#msg").text("");
				flog=true;
			}
	  }
	  
	  
	  <%--     var aid=${param.AttrId};
	    $.ajax({
			url:'<%=request.getContextPath()%>/productAttrDict/ProductAttrDict_listJson.action',
			type:'post',
			dataType:'json',
			data:{
				"t1.productAttr.id":aid
			}
			success:function(data){
				alert(data.list.length);
			}
		}); --%>
		  
	  	
	  	/* <c:forEach items="${list}" var="dict"> 
	  	    
		  	if(${dict.type}==1){
		  	    var a=${dict.value};
		  	    //alert(a);
		  	    $("#value1").val("aaaa");
		  	    //document.getElementById("value1").value=a;
		  	}
		  	if(${dict.type}==2){
		  	  	$("#value2").val("${dict.value}");
		  	}
		  	if(${dict.type}==3){
		  	  	$("#value3").val("${dict.value}");
		    }
	  	</c:forEach> */
	  
	
  	
  
    function submitForm(){
       /*  var productAttrName=$("#productAttrName").val();
    	productAttrName=productAttrName.trim();
    	if(productAttrName=="" || productAttrName==null){
    		$("#productAttrNameMng").attr("style","color:#a94442");
    		$("#productAttrName").attr("style","border:1px solid #a94442");
    		$("#msg").text("属性不能为空");
    		flog=false;
    	}else{
    		flog=true;
    	}
    	$("#defaultForm").data("bootstrapValidator").validate();
    	var flag = $("#defaultForm").data("bootstrapValidator").isValid();
    	if(flag && flog){
    		document.getElementById("defaultForm").submit();
    	} */
    	document.getElementById("defaultForm").submit();
    	
	}
    </script>
</head>
<body>
<div class="panel panel-primary">
  <div class="panel-heading">商品属性管理</div>
  <div class="panel-body">
    
	  <form id="defaultForm" class="form-horizontal" action="productAttrDict/ProductAttrDict_save.action?page=${page}" method="post">
	  <c:if test="${empty method}" ><!-- 添加 -->
	     <div class="form-group">
		    <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="productAttrNameMng">选择从属属性：</label>
		    <div class="col-sm-2">
                <input class="form-control" type="text" name="t.productAttr.name" id="productAttrName" onchange="checkAttrName()" readonly="readonly" value="${t.productAttr.name }">
                <input type="hidden" name="t.productAttr.id" id="productAttrId" value="${t.productAttr.id}">
                <div id="msg" style="color:#a94442;font-size:85%"></div>
		    </div>
		    <div class="col-sm-2">
                <input class="form-control" type="button" value="选择属性" onclick="chooseAttr()">
		    </div>
		 </div>
		  
		  <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label">
			                   原始值<input type="hidden" name="list[0].type" value="1">
			    </label>
			    <div class="col-sm-2">
	                <input class="form-control" type="text" name="list[0].value">
			    </div>
		  </div>
		  <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label">
			                   标准值<input type="hidden" name="list[1].type" value="2">
			    </label>
			    <div class="col-sm-2">
	                <input class="form-control" type="text" name="list[1].value">
			    </div>
		  </div>
		  <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label">
			                   简称<input type="hidden" name="list[2].type" value="3">
			    </label>
			    <div class="col-sm-2">
	                <input class="form-control" type="text" name="list[2].value">
			    </div>
		  </div>
		  <div class="form-group">
		    <div class="col-sm-offset-5 col-sm-7">
		      <input type="button" class="btn btn-default" onclick="addProductAttrDict()" value="保存">
		      <button type="reset" class="btn btn-default">重置</button>
		    </div>
		  </div>
	</c:if>	  
	
	
	
	      <c:if test="${!empty method}" >
	          <c:if test="${params!='dict'}" >
	          <input name="method" type="hidden" value="${method }">
			  
			  <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="productAttrNameMng">选择从属属性：</label>
			    <div class="col-sm-2">
	                <input class="form-control" type="text" name="t.productAttr.name" id="productAttrName" readonly="readonly" value="${list[0].productAttr.name }">
			        <input type="hidden" name="t.productAttr.id" value="${list[0].productAttr.id }">
			    </div>
			 </div>
			 </c:if>
			 
			 <div class="form-group">
			    <label id="label1" for="" class="col-sm-offset-3 col-sm-2 control-label">
			                   原始值<input type="hidden" name="type" value="1">
			    </label>
			    <div class="col-sm-2">
			        <s:iterator value="#list">
			            <c:if test="${type==1 }">
	                       <input class="form-control" type="text" name="value" id="value1" value="${value }">
	                       <input type="hidden" name="id" value="${id }">
					      
					    </c:if>
					</s:iterator>
					
			    </div>
			  </div>
			  
			  <div class="form-group">
				    <label id="label2"  for="" class="col-sm-offset-3 col-sm-2 control-label">
				                   标准值<input type="hidden" name="type" value="2">
				    </label>
				    <div class="col-sm-2">
			        <s:iterator value="#list">
			            <c:if test="${type==2 }">
	                       <input class="form-control" type="text" name="value" id="value2" value="${value }">
	                       <input type="hidden" name="id" value="${id }">
					    </c:if>
					</s:iterator>
					
			    </div>
			  </div>
			  <div class="form-group">
				    <label id="label3"  for="" class="col-sm-offset-3 col-sm-2 control-label">
				                   简称<input type="hidden" name="type" value="3">
				    </label>
				    <div class="col-sm-2">
				    <s:iterator value="#list">
			            <c:if test="${type==3 }">
	                       <input class="form-control" type="text" name="value" id="value3" value="${value }">
	                       <input type="hidden" name="id" value="${id }">
					       <input type="hidden" name="creationTime" value="${creationTime}">
					       <input type="hidden" name="creator" value="${creator}">
					    </c:if>
					</s:iterator>
				    </div>
			  </div>
			 
<%-- 			 <s:iterator value="#list">
			 <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="productAttrNameMng">
			        <c:if test="${type==1 }">原始值<input type="hidden" name="type" value="1"></c:if>
			        <c:if test="${type==2 }">标准值<input type="hidden" name="type" value="2"></c:if>
			        <c:if test="${type==3 }">简称<input type="hidden" name="type" value="3"></c:if>
			    </label>
			    <div class="col-sm-2">
			        <input type="hidden" name="id" value="${id }">
			        <input type="hidden" name="creationTime" value="${creationTime}">
			        <input type="hidden" name="creator" value="${creator}">
	                <input class="form-control" type="text" name="value" id="productAttrName" value="${value }">
			    </div>
			 </div>
			 </s:iterator> --%>
			 
			 
			<!--  <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label"> 
			                     原始值<input type="text" name="type" value="1">
			    </label>
			    <div class="col-sm-2">
			        <input class="form-control" type="text" name="value" value="">
			    </div>
			 </div>
			 <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label"> 
			                     标准值<input type="text" name="type" value="2">
			    </label>
			    <div class="col-sm-2">
			        <input class="form-control" type="text" name="value" value="">
			    </div>
			 </div>
			 <div class="form-group">
			    <label for="" class="col-sm-offset-3 col-sm-2 control-label"> 
			                     简称<input type="text" name="type" value="3">
			    </label>
			    <div class="col-sm-2">
			        <input class="form-control" type="text" name="value" value="">
			    </div>
			 </div> -->
			 <div class="form-group">
		    <div class="col-sm-offset-5 col-sm-7">
		      <input type="button" class="btn btn-default" onclick="updateProductAttrDict()" value="保存">
		      <button type="reset" class="btn btn-default">重置</button>
		    </div>
		  </div>
			  
		  </c:if>
		 
		  
      </form>
    
  </div>
  
</div>

</body>
</html>
